package interview.huawei.tjt.training.huisu;

import java.util.*;

/*
输入：n = 4, k = 2
输出：
[
  [2,4],
  [3,4],
  [2,3],
  [1,2],
  [1,3],
  [1,4],
]
 */
public class ZuHe {

    private static List<List<Integer>> result = new ArrayList<>();
    private static LinkedList<Integer> path = new LinkedList<>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        helper(n, k, 1);
        System.out.println(result);
    }

    public static void helper (int n, int k, int startIndex) {
        // 终止条件
        if (path.size() == k) {
//            result.add(path);
            result.add(new ArrayList<>(path));
            return;
        }

//        for (int i = startIndex; i <= n; i ++) {  // 未做剪枝处理
        for (int i = startIndex; i <= n - (k - path.size()) + 1; i ++) {  // 做了剪枝处理
            path.add(i);
            helper(n, k,i + 1);
            // 回溯
            path.removeLast();
        }
    }

}
